// 计算距离
export function getFlatternDistance(lat, lng) {
	var lat1 = Number(lat)
	var lng1 = Number(lng)
	// #ifdef H5
	var lat2 = uni.getStorageSync('locationInfo')[1]
	var lng2 = uni.getStorageSync('locationInfo')[0]
	// #endif
	// #ifdef MP-WEIXIN || MP-ALIPAY
	var lat2 = uni.getStorageSync('locationInfo').latitude
	var lng2 = uni.getStorageSync('locationInfo').longitude
	// #endif
	var EARTH_RADIUS = 6378137.0; //单位M
	var f = getRad((lat1 + lat2) / 2);
	var g = getRad((lat1 - lat2) / 2);
	var l = getRad((lng1 - lng2) / 2);

	var sg = Math.sin(g);
	var sl = Math.sin(l);
	var sf = Math.sin(f);

	var s, c, w, r, d, h1, h2;
	var a = EARTH_RADIUS;
	var fl = 1 / 298.257;

	sg = sg * sg;
	sl = sl * sl;
	sf = sf * sf;

	s = sg * (1 - sl) + (1 - sf) * sl;
	c = (1 - sg) * (1 - sl) + sf * sl;

	w = Math.atan(Math.sqrt(s / c));
	r = Math.sqrt(s * c) / w;
	d = 2 * w * a;
	h1 = (3 * r - 1) / 2 / c;
	h2 = (3 * r + 1) / 2 / s;

	return (d * (1 + fl * (h1 * sf * (1 - sg) - h2 * (1 - sf) * sg)) / 1000).toFixed(2);
}

function getRad(d) {
	var PI = Math.PI;
	return d * PI / 180.0;
}
